package com.gxy.learn.mybatisplus.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Description(通用返回)
 * author: Gao xueyong
 * Create at: 2021/12/1 下午9:13
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Result<T> {
    public static final int SUCCESS = 1;
    public static final String SUCCESSMSG = "成功";
    public static final int ERROR = 0;
    public static final String ERRORMSG = "失败";
    private int code;
    private String message;
    private T Data;

    public static <T>Result<T> success(T data) {
        return new Result<T>(SUCCESS,SUCCESSMSG,data);
    }
    public static <T>Result<T> success() {
        return new Result<T>(SUCCESS,SUCCESSMSG,null);
    }

    public static <T>Result<T> success(String message) {
        return new Result<T>(SUCCESS,message,null);
    }
    public static <T>Result<T> success(String message,T data) {
        return new Result<T>(SUCCESS,message,data);
    }
    public static <T>Result<T> error(T data) {
        return new Result<T>(ERROR,ERRORMSG,data);
    }
    public static <T>Result<T> error() {
        return new Result<T>(ERROR,ERRORMSG,null);
    }

    public static <T>Result<T> error(String message) {
        return new Result<T>(ERROR,message,null);
    }
    public static <T>Result<T> error(String message,T data) {
        return new Result<T>(ERROR,message,data);
    }

}

